package ca.ubc.cs304.library;

import java.io.BufferedReader;
import java.io.FileReader;

/**
 * Holds configuration for our project
 */
public class Configuration {
	
	/**
	 * HOW to use this file:
	 * To use the auto-configuration - create oracle.conf in your project folder
	 * (that's where src, bin, .project, .class, .classpath are)
	 * Place: connection string, user name, and password in that order:
     jdbc:oracle:thin:@localhost:1521:ug
     ora_abc
     A12345678
     */
	
	
	/**
	 * Defaults if not configured with oracle.conf
	 */
	private static final String DEFAULT_ORACLE_LOCATION = "jdbc:oracle:thin:@localhost:1521:ug";
	private static final String DEFAULT_ORACLE_USERNAME = "ora_w4c7";
	private static final String DEFAULT_ORACLE_PASSWORD = "a60584083";
	
	public static String oracleLocation;
	public static String oracleUsername;
	public static String oraclePassword;
	
	/**
	 * Try to load from configuration file oracle.conf in the present directory
	 */
	static {
		try {
			BufferedReader input = new BufferedReader(new FileReader("oracle.conf"));
			oracleLocation = input.readLine().trim();
			oracleUsername = input.readLine().trim();
			oraclePassword = input.readLine().trim();
			//System.out.println("Using loaded configuration (username " + oracleUsername + ")");
		} catch (Exception e) {
			System.out.println("Using default configuration.");
			oracleLocation = DEFAULT_ORACLE_LOCATION;
			oracleUsername = DEFAULT_ORACLE_USERNAME;
			oraclePassword = DEFAULT_ORACLE_PASSWORD;
		}
	}
}
